package handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

// TODO：管理员手动添加授权码
@WebServlet(name = "addAu", value = "/addAu")
public class addAu extends HttpServlet{
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;utf-8");
            PrintWriter out = resp.getWriter();
            String au = req.getParameter("au");
            int level = Integer.valueOf(req.getParameter("level")).intValue();
            System.out.println(au+level);
            boolean ok = false;
            try {
                ok = Manager.byHande(au,level);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            if (ok){
                    out.print("添加成功");
                }else {
                    out.print("添加失败");
                }

        }
}
